<%@page import="entity.User"%>
<%@page import="zcServace.UserServace"%>
<%@page import="zcServace.impl.UserServaceinpl"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="css/NewFile.css" />
<script type="text/javascript" src="js/index2.js" ></script>
<script type="text/javascript" src="js/jquery-1.12.4.min.js" ></script>
</head>
<body>
	<%
		//从request中拿到cookies
		Cookie[]cookies=request.getCookies();
		Cookie usercookies=null;
		if(cookies!=null){
			for(Cookie cookie:cookies){
				//将取到的cookie的name与之前存储到的cookie的键比对
				if(cookie.getName().equals("usercookie")){
					//如果比对成功就赋值给usercookies
					usercookies=cookie;
				}
			}
			if(usercookies!=null){
				String  value=usercookies.getValue();
				System.out.println(value);
				String username=value.split(",")[0];
				String userpassword=value.split(",")[1];
				UserServace us=new UserServaceinpl();
				User user = us.selectAllUser(username, userpassword);
				if(username.equals(user.getUsername())&& userpassword.equals(user.getPassword())){
					response.sendRedirect("main.jsp");
				}else{
					response.sendRedirect("login.jsp");
				}
			}
		}
		%>
	<div class="content">
		<div class="title">
			<span class="title_con">90度房产管理系统</span>
	</div>
	<!--表单验证-->
	<div class="con_title">
			<span class="con_title_sp">欢迎登录90度房产管理系统</span>
	</div>
	<form action="UserServlet" method="get" class="mainForm">
	
	<div class="normalInput">
	<input type="text" class="name" name="username" placeholder="用户名" style="font-size: 16px;background: rgba(0,0,0,0);border:1px solid black;"autocomplete="off"/>
	<span class="error1"></span>
	</div>
	
	<div class="normalInput2">
	<input type="password" class="pwd" name="userpassword" placeholder="密码" style="font-size: 16px;background: rgba(0,0,0,0);border:1px solid black;"/>
	<input type="text" class="pwd2" name="userpassword2" placeholder="密码" style="font-size: 16px;background: rgba(0,0,0,0);border:1px solid black;"/>
	<p style="font-size: 14px; color: #666666;"><input type="radio" name="zidongdenglu" class="zidongdenglu" onclick="if(this.c==1){this.c=0;this.checked=0}else this.c=1" c="0"/>自动登陆</p>
	<p class="pbiaoqian" isshow="false"><i class="pbiaoqian2"></i></p>
	<span class="error2"></span>
	</div>
	<input type="submit" class="denglu" value="登陆"/>
	</div>
	<script type="text/javascript">
		$(function(){
	$(".name").focus(function(){
		$(".error1").html("");
		$(this).css("border","1px solid black")
	});
	$(".pwd").focus(function(){
		$(".error2").html("");
		$(this).css("border","1px solid black")
	});
	/*隐藏的密码框*/
	$(".pwd2").focus(function(){
		$(".error2").html("");
		$(this).css("border","1px solid black")
		
	});
	/*账号栏验证*/
	$(".name").blur(function(){
	var myReg = /^[a-zA-Z0-9_]{0,}$/;
	if($(".name").val()==""){
		$(".error1").html("用户名不能为空");
		$(".error1").show()
		$(this).css("border","1px solid red");
	}
	if(!myReg.test($(".name").val())){
	$(".error1").html("用户名不能有文字和特殊符号");
		$(".error1").show()
		$(this).css("border","1px solid red");
	}
	});
	/*密码栏验证*/
	$(".pwd").blur(function(){
	var myReg = /^[a-zA-Z0-9_]{0,}$/;
	if($(".pwd").val()==""){
		$(".error2").html("密码不能为空");
		$(".error2").show()
		$(this).css("border","1px solid red");
	}
	if(!myReg.test($(".pwd").val())){
	$(".error2").html("密码不能有文字和特殊符号");
	$(".error2").show()
		$(this).css("border","1px solid red");
	}
	});
	/*第二个隐藏的密码框*/
	$(".pwd2").blur(function(){
	var myReg2 = /^[a-zA-Z0-9_]{0,}$/;
	if($(".pwd2").val()==""){
		$(".error2").html("密码不能为空");
		$(".error2").show()
		$(this).css("border","1px solid red");
	}
	if(!myReg2.test($(".pwd2").val())){
	$(".error2").html("密码不能有文字和特殊符号");
	$(".error2").show()
		$(this).css("border","1px solid red");
	}
	});
	
	
	/*密码可见*/
	$(".pbiaoqian").click(function(){
		if($(".pbiaoqian").attr("isshow")=="false"){
		$(".pwd").hide();
		$(".pwd2").val($(".pwd").val());
		$(".pwd2").show();
		$(".pbiaoqian2").css("background-position","-33px -93px");
		if($(".pwd").val()==""){
		$(".pwd2").css("border","1px solid red");
		$(".error2").show();
		$(".error2").html("密码不能为空");
		}else{
		$(".pwd2").css("border","1px solid black");
		$(".error2").html("");
		}
		$(".pbiaoqian").attr("isshow","true");
		
		}else{
		$(".pwd2").hide();
		$(".pwd").val($(".pwd2").val());
		$(".pwd").show();
		$(".pbiaoqian2").css("background-position","-63px -93px");
		if($(".pwd2").val()==""){
		$(".pwd").css("border","1px solid red");
		$(".error2").show();
		$(".error2").html("密码不能为空");
		}else{
		$(".pwd2").css("border","1px solid black");
		$(".error2").html("");
		}	
		$(".pbiaoqian").attr("isshow","false");
		
		}
		
	});
	})

	</script>
	
</form>
</body>
</html>